<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="../../plugins/layui/css/layui.css"/>
    <link rel="stylesheet" href="../../css/normalize.css"/>
    <link rel="stylesheet" href="../../css/fa.css"/>
    <link rel="stylesheet" href="../../css/icon.css"/>
    <link rel="stylesheet" href="../../css/ares_animate.min.css"/>
    <link rel="stylesheet" href="../../css/ares_hover_variant.min.css"/>
    <link rel="stylesheet" href="../../css/ares_reboot.css"/>
    <link rel="stylesheet" href="../../css/app.min.css"/>
    <link rel="stylesheet" href="../../css/iframe.css"/>
    <link rel="stylesheet" href="../../css/print.css"/>
    <style>

    </style>
</head>

<body class="print-wrap">
<button id="print-btn" class="layui-btn layui-btn-xs ares-d-print-none ares-position-absolute ares-absolute-tr-offset">打印</button>
<h3>基本信息</h3>
<div class="ares-mb emr-info ares-border-bottom"></div>
<div class="creator-wrap ares-text-right"></div>
<h3>评估详情</h3>
<table class="layui-hide" id="table" lay-filter="table"></table>


<script type="text/html" id="tableBar">
    {{#  if(d.therapist.id == d.currentUserId && d.status == 1){ }}
    <button class="layui-btn layui-btn-xs" lay-event="check">查看</button>
    {{# } }}
</script>
<script type="text/javascript" src="../../plugins/html2canvas.min.js"></script>
<script type="text/javascript" src="../../plugins/layui/layui.js"></script>
<script type="text/javascript" src="../../aresExtends/config/layuiConfig.js"></script>
<script>
    var init;
    layui.use(['table', 'dateFilters', 'commonServices', 'greyServices', 'utils', 'store', 'qs', 'printArea'], function (table, dateFilters, commonServices, greyServices, utils, store, qs, printArea) {
        var selectPrcpId, emrId, isReferralHistory;
        init = function () {
            var localHash = location.hash,
                queryStr = localHash.split('?')[1],
                routerParams = top.layui.routers.params,
                routerQuery = queryStr ? qs.parse(queryStr) : {};
            console.log(localHash, queryStr, routerParams, routerQuery)
            selectPrcpId = routerParams.prcpId;
            emrId = routerParams.emrId;
            isReferralHistory = routerQuery.isReferralHistory;
            getPatientInfo();
            getDetail();
        }
        init();

        /**
         * @author: ares
         * @date: 2021/3/30 11:51
         * @description: 打印
         */
        $('#print-btn').on('click', function () {
            html2canvas($('#table').next()[0]).then(canvas => {
                $('.print-img').remove();
                var dataUrl = canvas.toDataURL();
                $('#table').before('<img class="print-img ares-d-print-block" src="'+dataUrl+'"/>');
                $('.print-wrap').printArea();
            });

        })

        /**
         * @author: ares
         * @date: 2021/3/30 16:31
         * @description: 获取详情
         */
        function getDetail() {
            greyServices.grey_get_prescription(selectPrcpId, emrId, isReferralHistory).then(function (res) {
                var data = res.data,
                    list = data.prcp_item_list || [];
                $('.creator-wrap').empty().append('<b>创建者: ' + data.creator.name + '</b>' +
                    '<b class="ares-ml-lg">创建时间: ' + dateFilters.dateTimeFormat(data.create_time) + '</b>');
                $.each(list, function (idx, item) {
                    item.currentUserId = store.get('profile').id
                })
                table.render({
                    elem: '#table',
                    data: list,
                    cellMinWidth: 80,
                    cols: [[
                        {title: '病种', templet: '<span>{{d.disease.name}}</span>'},
                        {title: '评估项目', templet: '<span>{{d.gauge.name}}</span>'},
                        {title: '医嘱', field: 'prescribed'},
                        {title: '评估人', templet: '<span>{{d.current_therapist.name}}</span>'},
                        {
                            title: '状态',
                            templet: function (d) {
                                return utils.setEnableOrDisable(d.status,'完成|未完成');
                            }
                        },
                        {title: '操作', fixed: 'right', templet: '#tableBar'}
                    ]]
                });
                table.on('tool(table)', function (obj) {
                    var data = obj.data;
                    switch (obj.event) {
                        case 'check':
                            checkGauge(data.id);
                            break;
                    }
                });
            });
        }

        /**
         * @author: ares
         * @date: 2021/3/30 16:31
         * @description: 查看评估
         * @param{string}prcpItemId
         */
        function checkGauge(prcpItemId) {
            var query = {
                prcpItemId: prcpItemId
            };
            utils.pushTopRoute('/evaluation/gauge', query)
        }

        /**
         * @author: ares
         * @date: 2021/3/10 10:49
         * @description: 获取患者基本信息
         */
        function getPatientInfo() {
            commonServices.getEmrInfoService(emrId, null, null, $('.emr-info'))
        }
    })
</script>
</body>
</html>
